package es.ats.codington.festival.mappers;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import es.ats.codington.festival.domain.LargeBusiness;
import es.ats.codington.festival.domain.Museum;
import es.ats.codington.festival.domain.Park;
import es.ats.codington.festival.domain.Places;
import es.ats.codington.festival.domain.Stadium;
import es.ats.codington.festival.domain.Theater;
import es.ats.codington.festival.domain.TouristAttractions;
import es.ats.codington.festival.domain.TraditionalMarkets;
import es.ats.codington.festival.domain.Zoo;

public class PlaceMapper implements RowMapper<Places>{

	@Override
	public Places mapRow(ResultSet resultSet, int nRow) throws SQLException {
		Places place;
		
		switch (resultSet.getInt("placetype")) {
		case LargeBusiness.placeType:
			place = new LargeBusiness(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
			
		case Museum.placeType:
			place = new Museum(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;

		case Park.placeType:
			place = new Park(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
			
		case Stadium.placeType:
			place = new Stadium(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
			
		case Theater.placeType:
			place = new Theater(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
			
		case TouristAttractions.placeType:
			place = new TouristAttractions(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
			
		case TraditionalMarkets.placeType:
			place = new TraditionalMarkets(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
			
		case Zoo.placeType:
			place = new Zoo(resultSet.getInt("placeid"),resultSet.getString("placename"),resultSet.getInt("capacity"),resultSet.getString("placedescription"),resultSet.getString("zone"));
			break;
		default: 
			place = new Museum();
			break;
		}
		
		
		return place;
	}

}